package my.test.groups.secondcommon;


import java.util.ArrayList;

/**
 * @Author 许玉康
 * @Date 2019/9/20 16:35
 */
public class client {

    public static void main(String[] args) {
        //首先组装一个组织结构出来
        Branch ceo = compositeCorpTree();
        //把ceo的信息打印出来
        System.out.println(ceo.getInfo());
        System.out.println(getTreeInfo(ceo));
    }

    public static Branch compositeCorpTree() {
        //首先产品总经理
        Branch root  = new Branch("王大麻子", "总经理" ,100000);
        //把三个部门经理产生出来
        Branch developDep = new Branch("赵大瘸子","研发部门经理", 10000);
        Branch salesDep = new Branch("马耳掴子", "销售部经理", 20000);
        Branch financeDep = new Branch("赵三驼子", "财务部经理", 30000);

        //再把三个小组长生产出来
        Branch firstDevGroup = new Branch("杨三也写", "开发组一组组长", 5000);
        Branch secondDevGroup = new Branch("舞大棒催", "开发组二组组长", 6000);

        //把所有小兵生产出来
        Leaf a  = new Leaf("a", "开发人员", 2000);
        Leaf b  = new Leaf("b", "开发人员", 2000);
        Leaf c  = new Leaf("c", "开发人员", 2000);
        Leaf d  = new Leaf("d", "开发人员", 2000);
        Leaf e  = new Leaf("e", "开发人员", 2000);
        Leaf f  = new Leaf("f", "开发人员", 2000);
        Leaf g  = new Leaf("g", "开发人员", 2000);
        Leaf h  = new Leaf("h", "开发人员", 2000);
        Leaf i  = new Leaf("i", "销售人员", 2000);
        Leaf j  = new Leaf("j", "销售人员", 2000);
        Leaf k  = new Leaf("k", "CEO秘书", 2000);
        Leaf zhengLaoLiu  = new Leaf("郑老六", "研发部副经理", 20000);

        //开始组装
        //ceo下有三个部门经理和一个秘书
        root.addSubordinate(developDep);
        root.addSubordinate(salesDep);
        root.addSubordinate(financeDep);

        //总经理下还有一个秘书
        root.addSubordinate(k);
        //研发部经理
        developDep.addSubordinate(firstDevGroup);
        developDep.addSubordinate(zhengLaoLiu);
        developDep.addSubordinate(secondDevGroup);

        //两个开发小组
        firstDevGroup.addSubordinate(a);
        firstDevGroup.addSubordinate(b);
        firstDevGroup.addSubordinate(c);
        secondDevGroup.addSubordinate(d);
        secondDevGroup.addSubordinate(e);
        secondDevGroup.addSubordinate(f);

        //销售部
        salesDep.addSubordinate(h);
        salesDep.addSubordinate(i);

        //最后一个财务
        financeDep.addSubordinate(j);
        return root;
    }


    //遍历所有的树枝节点，打印出信息
    private static String getTreeInfo(Branch root) {
        ArrayList<ICorp> subordinateList = root.getSubordinate();
        String info = "";
        for(ICorp s : subordinateList) {
            if(s instanceof  Leaf) {
                info = s.getInfo() + "\n";
            } else {
                info = info + s.getInfo() + "\n" + getTreeInfo((Branch) s);
            }
        }
        return info;

    }
}
